// pages/list/avatars.js
var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');


var GetList = function (that) {
  let token = wx.getStorageSync('token');
  wx.showNavigationBarLoading();
  util.request(api.SpreaderList, { token: token, auth: that.data.status }).then(function (res) {
    wx.hideNavigationBarLoading();
    if (res.code === '200') {
      that.setData({
        users: res.datas
      })
    }
  });
}
Page({
  data: { status: "1", users: {} },
  onLoad: function (options) {
    this.setData({
      status: "1"
    })
    GetList(this);
  },
  onReady: function () {
    // 页面渲染完成
  },
  onShow: function () {
    // 页面显示
  },
  onHide: function () {
    // 页面隐藏
  },
  onUnload: function () {
    // 页面关闭
  },
  tabAuthed: function () {
    this.setData({
      status: "1"
    })
    GetList(this);
  },
  tabUnAuth: function () {
    this.setData({
      status: "0"
    })
    GetList(this);
  },
  tabAuthRejected: function () {
    this.setData({
      status: "2"
    })
    GetList(this);
  },
  adit: function (event) {
    var id = event.currentTarget.dataset.id;
    var auth = "1";
    let token = wx.getStorageSync('token');
    wx.showActionSheet({
      itemList: ['同意', '驳回'],
      success: function (res) {
        if (res.tapIndex == 0) {
          util.request(api.AuditSpreader, { token: token, id: id, auth: "1" }).then(function (res) {
            wx.hideNavigationBarLoading();
            if (res.code === '200') {
              wx.showToast({
                title: '审核成功',
              })
            }
          });
        } else if (res.tapIndex == 1) {
          util.request(api.AuditSpreader, { token: token, id: id, auth: "2" }).then(function (res) {
            wx.hideNavigationBarLoading();
            if (res.code === '200') {
              wx.showToast({
                title: '审核成功',
              })
            }
          });
        }

      },
      fail: function (res) {
        console.log(res.errMsg)
      }
    })


  }
})